package com.fjrcloud.controller;

import com.fjrcloud.entity.TemplateCurrent;
import com.fjrcloud.entity.TemplateWarehouse;
import com.fjrcloud.exception.BusinessException;
import com.fjrcloud.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by shengjian.lin on 17-1-4.
 */
@Controller
@RequestMapping("template")
public class HtmlTemplateController {

    @Autowired
    TemplateService service;

    @RequestMapping("list")
    public String list(Model model){

        Page<TemplateCurrent> page = service.list(null,null);

        model.addAttribute("templates",page.getContent());

        return "template-manage";
    }
    @RequestMapping("edit")
    public String edit(Model model,Integer id) throws BusinessException {

        if(id != null) {
            TemplateCurrent current = service.get(id);
            model.addAttribute("template", current);

            Page<TemplateWarehouse> page = service.versions(id, null, null);
            model.addAttribute("versions", page.getContent());
        }
        return "template-edit";
    }
}
